package com.etoak.service;

import com.alibaba.fastjson.JSONObject;
import com.etoak.bean.Email;
import com.etoak.bean.User;
import com.etoak.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: activemq-SpringMVC
 * @description:
 * @author: 管浩杰
 * @create: 2021-03-17 10:46
 **/

@Service
@Slf4j
public class UserService {
    @Autowired
    UserMapper userMapper;

    @Autowired
    private JmsTemplate jmsTemplate;


    @Transactional
    public int addUser(User user){

        Email email = new Email(user.getEmail(), "激活邮件", "请点击链接, http://www.hojay.top:9090" + user.getName());
        log.info("邮件系统");
        jmsTemplate.send("email", session -> {
            log.info("email" + email.toString());
           return session.createTextMessage(JSONObject.toJSONString(email));
        });
        return userMapper.addUser(user);
    }

}
